Repository navigation
Add generated inference for Permuto and multilevel LoD - #539
Open
shsolanki-1 wants to merge 6 commits into
Open
shsolanki-1 wants to merge 6 commits into
shsolanki-1 wants to merge 6 commits into
Conversation
Register the native Permuto encoding and a hard MultiLevelEncodingLoD wrapper for training, with parameter-gradient, input-gradient, and double backward paths. Add non-JIT FullyFusedMLP double backward for one hidden ReLU layer without an output activation, and let the torch bindings skip the second-order input gradient when callers do not need it. NetworkWithInputEncoding chains double backward through its encoding and network. Network::backward takes the network output, which double backward does not receive, so it is recomputed from the saved encoding output on that path. Storing a copy in forward instead would cost every pass that prepares first-order input gradients. The torch bindings compute the second-order input gradient whenever the input requires a gradient, including when the parameters are frozen. tcnn.Network wraps its network in an Identity encoding, so Identity now implements double backward: it passes the scaled second-order gradient upstream, and its input Hessian is zero because it is linear. Without it, frozen-parameter tcnn.Network double backward would fail in the encoding.
Dispatch the existing native implementation over the public dimension and feature-width matrix. Canonicalize aliases and validate configuration before template construction while preserving the existing 5D/two-feature artifact contract. Cap AoS transpose geometry so wide outputs stay within CUDA block-size limits.
Wrap any multilevel encoding so Grid and Permuto share one hard or soft LoD path. Preserve base layouts, strides, parameters, streams, and double backward by staging incompatible matrices through the preferred layout and retaining unweighted soft outputs. Expose level counts through the minimal base interface and align Grid derivative cutoffs with the forward predicate at the epsilon boundary.
A CUDA module is valid only in the context that loaded it, so JIT kernels and MLP parameter-conversion kernels are cached per CUDA context and each module is unloaded in its owning context. A thread without a current context binds the current device's primary context before the lookup, as its first CUDA runtime call would, so JIT inference still works from a fresh thread.
Generate public inference evaluators for Permuto and wrapper-owned LoD masking through the standard device-function ABI. Disable generated execution when mutable multilevel controls would make cached source stale. Propagate validity through composed models, preserve float reduction behavior, and select derivative execution from the supplied forward context. Keep generated contexts and derivatives unsupported, so training disables JIT before context allocation and uses native forward and backward.
shsolanki-1
force-pushed
the
codex/permuto-lod-implementation
branch
from
September 29, 2026 10:16
c976ac7 to
f645cac
Compare
shsolanki-1
marked this pull request as ready for review
September 30, 2026 05:46
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
This PR depends on #538. GitHub shows the combined stack until #538 lands. The incremental review range is
codex/permuto-lod-native...codex/permuto-lod-implementation.Summary
MultiLevelEncodingLoD.CompositeandNetworkWithInputEncoding.Motivation
Permuto and the generalized LoD wrapper provide native forward and derivative paths in #538, but they do not provide generated evaluators for fused inference. The existing runtime-compilation cache also stores one context-bound CUDA module per object. Reusing that module from another CUDA context is invalid.
This change adds the generated inference path and makes the shared runtime-compilation cache safe for objects used from multiple CUDA contexts, including PyTorch
DataParallelinference.Execution Contract
Generated support is limited to inference. The generated functions retain the standard three-argument device-function application binary interface and do not allocate a generated forward context.
Training falls back to the native forward and derivative paths before a JIT forward context is created. Generated backward and generated double backward remain unsupported.
Double backward after a JIT forward raises
Cannot use native double backward with a JIT forward context.and disables JIT for the object, because no model provides generated double backward. Later iterations use the native path. Before this change, the same sequence failed withstd::bad_cast.Enabling JIT after it was disabled clears the object's cached kernels. With the PyTorch default runtime-compilation cache directory, the kernels reload from disk in about 1 ms. Without a cache directory, the next JIT call recompiles.
Restrictive scalar or per-element multilevel caps disable JIT for the affected object. This prevents cached generated source from embedding stale mutable state. Backward and double backward select their execution path from the supplied forward context instead of the object's current JIT setting.
Validation
TCNN_CUDA_ARCHITECTURES=89. Passed focused native Permuto and LoD coverage, generated-inference and JIT-context cases, CUDA runtime-compilation cache cases, and PyTorch generated-inference and two-GPUDataParallelcoverage.TCNN_CUDA_ARCHITECTURES=120on one RTX PRO 6000 Blackwell:test_encodings,test_grid,test_jit_losses,test_permuto(43 test cases), andtest_rtc_device_cache(3 test cases, including JIT inference from a thread without a current CUDA context) pass. The two multi-GPU cache cases return early with a warning on this single-GPU machine. Intest_networks, the existing JIT tolerance testVarious invariance checks for neural networksfails with the same 200 assertions on the unmodified base commit; the other test cases pass.sm_120:bindings/torch/tests/test_permuto.pypasses 11 tests and skips the two-GPUDataParalleltest.git diff --check.